﻿using AutoMapper;
using CommonManagement.Applcation.Command;
using ERPPublic.eneity;
using MediatR;
using ProcurementManagement.Applcation.Command.ProvinceCommand;
using ProcurementManagement.Infrstructre.Imp;
using ProcurementManagement.Infrstructre.Interface;

namespace ProcurementManagement.Applcation.CommandHanlers.ProvinceCommandHandlers
{
    public class CityCommandhandlers : IRequestHandler<CityCommand, List<City>>
    {
        private readonly ICityRepository _cityRepository;
        protected readonly IMapper mapper;
        public CityCommandhandlers(ICityRepository cityRepository, IMapper mapper)
        {
            _cityRepository = cityRepository;
            this.mapper = mapper;
        }
        public async Task<List<City>> Handle(CityCommand request, CancellationToken cancellationToken)
        {
            var list = (await _cityRepository.GetAll()).Where(x => x.ProvinceId == request.ProvinceId).ToList();
         
            return mapper.Map<List<City>>(list);
        }
    }
}
